<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\collection\BackendCommon;
use common\helpers\PublicFun;
use backend\config\routeParams;


/**
 * Enterprise controller
 */
class ExamineController extends Controller
{

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    public  function beforeAction($action){
        if(BackendCommon::init()){
            if(BackendCommon::rbac()){
                return true;
            }else{
                Yii::$app->response->redirect( ['site/error']);
            }
        }else{
            Yii::$app->response->redirect( ['login/index']);
        }
    }
    //试用申请列表
    public function actionProbation()
    {
        return $this->render('probation');
    }
    //试用申请列表
    public function actionEnterprise()
    {
        return $this->render('enterprise');
    }
    //提现审核列表
    public function actionWithdraw()
    {
        return $this->render('withdraw');
    }

    //获取试用申请列表（待审核）
    public function actionGetProbationApplyList()
    {
        $datapost = Yii::$app->request->post();
        $datapost = Common::ArrayFilter($datapost);
        $url = routeParams::HttpUrl('PCProbationApplyGetList');
        $result = PublicFun::PostPackage($datapost, $url);
        $result = json_decode($result['Body'],true);
        $ret = [
            'PageNo' => $datapost['PageNo'],
            'PageSize' => $datapost["PageSize"],
            'total' => $result["TotalCount"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }
    //审核试用申请
    public function actionProbationAudit()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCProbationApplyAudit');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }

    //获取试用申请列表（待审核）
    public function actionGetEnterpriseApplyList()
    {
        $datapost = Yii::$app->request->post();
        $datapost = Common::ArrayFilter($datapost);
        $url = routeParams::HttpUrl('PCEnterpriseInfoApplyGetList');
        $result = PublicFun::PostPackage($datapost, $url);
        $result = json_decode($result['Body'],true);
        $ret = [
            'PageNo' => $datapost['PageNo'],
            'PageSize' => $datapost["PageSize"],
            'total' => $result["TotalCount"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }

    //审核企业资料
    public function actionEnterpriseAudit()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCEnterpriseInfoAudit');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }
    //获取企业提现申请列表
    public function actionGetWithdrawList()
    {
        $datapost = Yii::$app->request->post();
        $datapost = Common::ArrayFilter($datapost);
        $url = routeParams::HttpUrl('PCENTWithdrawApplyGetList');
        $result = PublicFun::PostPackage($datapost, $url);
        $result = json_decode($result['Body'],true);
        $ret = [
            'PageNo' => $datapost['PageNo'],
            'PageSize' => $datapost["PageSize"],
            'total' => $result["TotalCounts"],
            'data' => $result['Models']
        ];
        die(json_encode($ret));
    }
    //审核企业资料
    public function actionWithdrawAudit()
    {
        $JsonData = Yii::$app->request->post();
        //数据过滤
        $JsonData = Common::ArrayFilter($JsonData);
        $JsonData['MytipId'] =  Common::GetMytipId();
        $url = routeParams::HttpUrl('PCENTWithdrawAudit');
        $result = PublicFun::PostPackage($JsonData, $url);
        $result = $result = json_decode($result['Body'],true);
        die(json_encode($result));
    }


}
